home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstNext.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  2.6 KB  |  114 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.8
  10. date     88.11.17.20.53.40;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.8
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.44.
  23. @
  24. text
  25. @/*-
  26.  * LstNext.c --
  27.  *    Return the next node for a list.
  28.  *    The sequential functions access the list in a slightly different way.
  29.  *    CurPtr points to their idea of the current node in the list and they
  30.  *    access the list based on it. Because the list is circular, Lst_Next
  31.  *    and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
  32.  *    used to determine when to stop.
  33.  *
  34.  * Copyright (c) 1988 by University of California Regents
  35.  *
  36.  * Permission to use, copy, modify, and distribute this
  37.  * software and its documentation for any purpose and without
  38.  * fee is hereby granted, provided that the above copyright
  39.  * notice appears in all copies.  Neither the University of California nor
  40.  * Adam de Boor makes any representations about the suitability of this
  41.  * software for any purpose.  It is provided "as is" without
  42.  * express or implied warranty.
  43.  */
  44. #ifndef lint
  45. static char *rcsid =
  46. "$Id: lstNext.c,v 1.8 88/11/17 20:53:40 adam Exp $ SPRITE (Berkeley)";
  47. #endif lint
  48.  
  49. #include    "lstInt.h"
  50.  
  51. /*-
  52.  *-----------------------------------------------------------------------
  53.  * Lst_Next --
  54.  *    Return the next node for the given list.
  55.  *
  56.  * Results:
  57.  *    The next node or NILLNODE if the list has yet to be opened. Also
  58.  *    if the list is non-circular and the end has been reached, NILLNODE
  59.  *    is returned.
  60.  *
  61.  * Side Effects:
  62.  *    the curPtr field is updated.
  63.  *
  64.  *-----------------------------------------------------------------------
  65.  */
  66. LstNode
  67. Lst_Next (l)
  68.     Lst              l;
  69. {
  70.     register ListNode    tln;
  71.     register List     list = (List)l;
  72.     
  73.     if ((LstValid (l) == FALSE) ||
  74.     (list->isOpen == FALSE)) {
  75.         return (NILLNODE);
  76.     }
  77.     
  78.     list->prevPtr = list->curPtr;
  79.     
  80.     if (list->curPtr == NilListNode) {
  81.     if (list->atEnd == Unknown) {
  82.         /*
  83.          * If we're just starting out, atEnd will be Unknown.
  84.          * Then we want to start this thing off in the right
  85.          * direction -- at the start with atEnd being Middle.
  86.          */
  87.         list->curPtr = tln = list->firstPtr;
  88.         list->atEnd = Middle;
  89.     } else {
  90.         tln = NilListNode;
  91.         list->atEnd = Tail;
  92.     }
  93.     } else {
  94.     tln = list->curPtr->nextPtr;
  95.     list->curPtr = tln;
  96.  
  97.     if (tln == list->firstPtr || tln == NilListNode) {
  98.         /*
  99.          * If back at the front, then we've hit the end...
  100.          */
  101.         list->atEnd = Tail;
  102.     } else {
  103.         /*
  104.          * Reset to Middle if gone past first.
  105.          */
  106.         list->atEnd = Middle;
  107.     }
  108.     }
  109.     
  110.     return ((LstNode)tln);
  111. }
  112.  
  113. @
  114.